﻿using FirstProject.Views;
using Microsoft.Xaml.Behaviors.Core;
using Prism.Mvvm;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Input;
using System.Windows;
using Prism.Dialogs;
using Prism.Commands;

namespace FirstProject.ViewModels
{
    public class LoginViewModel: BindableBase
    {

        private string _username;
        public string Username
        {
            get => _username;
            set { SetProperty(ref _username, value);}
        }

        private string _password;
        public string Password
        {
            get => _password;
            set { SetProperty(ref _password, value); }
        }

        public ICommand LoginCommand => new ActionCommand(ExecuteLogin);
        public ICommand CancelCommand => new ActionCommand(ExecuteCancel);

        private void ExecuteLogin()
        {
            if (string.IsNullOrWhiteSpace(Username) || string.IsNullOrWhiteSpace(Password))
            {
                MessageBox.Show("请输入用户名和密码");
                return;
            }
            // 实际验证逻辑
            if (ValidateCredentials(Username, Password))
            {
                new MainView().Show();
                Application.Current.MainWindow?.Close();
            }
        }

        private void ExecuteCancel()
        {
            Application.Current.Shutdown();
        }

        public bool ValidateCredentials(string username, string password)
        {
            // 这里可以实现具体的验证逻辑
            // 例如，检查用户名和密码是否匹配数据库中的记录
            if (username == "admin" && password == "password")
            {
                return true;
            }
            return false;
        }
    }
}

